﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using DeviceInfoManage.BusinessLogicLayer;
using System.Text;

public partial class BurstList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        /*对进行查询的设备类型下拉框各项进行设置*/
        if (!IsPostBack)
        {
            if (Session["adminUserName"] == null)
            {
                Response.Redirect("logout.aspx");
            }
            if (Session["adminType"].ToString() != "管理员")
            {
                btnDel.Visible = false;
            }
            ddlPrincipal.DataSource = (new MaintPerson()).GetMaintPersonName();
            ddlPrincipal.DataTextField = "maintPersonName";
            ddlPrincipal.DataValueField = "maintPersonId";
            ddlPrincipal.DataBind();
            ddlPrincipal.Items.Insert(0, new ListItem("=请选择=", ""));

            Btn_Query_Click(null, null);
        }


    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            //当鼠标选择某行时变颜色
            e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#00ffee';");
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
        }
    }

    protected void Btn_Query_Click(object sender, EventArgs e)
    {
        /*取得各个查询字段的内容然后调用业务类的QueryDevice函数进行查询*/
        StringBuilder strSql = new StringBuilder();
        if (ddlPrincipal.SelectedValue != "") { strSql.Append(" UserName = '" + ddlPrincipal.SelectedItem.Text + "'"); }
        if (!string.IsNullOrEmpty(txtDate1.Text)) { strSql.Append(" AND Date >= convert(datetime, '" + txtDate1.Text + "')"); }
        if (!string.IsNullOrEmpty(txtDate2.Text)) { strSql.Append(" AND Date <= convert(datetime, '" + txtDate2.Text + "')"); }
        if (!string.IsNullOrEmpty(txtErrorReason.Text)) { strSql.Append(" AND Reason like '%" + txtErrorReason.Text + "%'"); }
        if (strSql.ToString().StartsWith(" AND")) { strSql = strSql.Remove(0, 4); }
        this.GridView1.DataSourceID = null;
        this.GridView1.DataSource = (new BurstEvent()).GetList(strSql.ToString());
        this.GridView1.DataBind();

    }

    protected void btnDel_Click(object sender, EventArgs e)
    {
        for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
        {
            CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("cbox");
            if (cbox.Checked == true)
            {
                int docid = int.Parse(GridView1.DataKeys[i].Value.ToString());
                (new BurstEvent()).Delete(docid);
                //Response.Write("<script>alert('" + outInfo + "');</script>");
            }
        }
        Response.Redirect("~/BurstList.aspx");
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        Btn_Query_Click(null, null);
    }
}
